#!/bin/bash
# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu
set -e

source ~/miniconda3/etc/profile.d/conda.sh
conda activate coin2_env

echo '# ---------------------------------------------------------------------------- #'
echo '#                                  Buildifier                                  #'
echo '# ---------------------------------------------------------------------------- #'

set +e
git diff origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH...HEAD --name-only --diff-filter=ACDMRT \
| rg -v "external|third_party|experimental" \
| rg "WORKSPACE|BUILD|(\.bzl)"

status=$?
set -e

if [ $status -eq 0 ]
then
bazel run //:buildifier
else
echo 'no WORKSPACE or BUILD file changed.'
fi
